<template>
  <div class="app-container">
    <div class="filter-container">
      <el-page-header @back="backUp" class="backUp" :content="type_name"></el-page-header>
      <el-button class="filter-item" type="primary" icon="el-icon-plus" @click="handleCreate">
        添加类型
      </el-button>
    </div>
    <el-table
      :data="data"
      style="width: 100%;margin-bottom: 20px;"
      row-key="id"
      border
      default-expand-all
      :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
    >
      <el-table-column prop="type_name" label="类型名称" align='center'/>
      <el-table-column prop="type_key" label="类型标记" align='center'/>
      <el-table-column label="单选/多选" align='center'>
        <template slot-scope="item">
          {{item.row.select_type==1?'多选':'单选'}}
        </template>
      </el-table-column>
      <el-table-column label="显示状态" align='center'>
        <template slot-scope="item">
          {{item.row.show_type==1?'司机':item.row.show_type==2?'非司机':item.row.show_type==3?'企业':'全部'}}
        </template>
      </el-table-column>
      <el-table-column label="是否必填" align='center'>
        <template slot-scope="item">
          {{item.row.is_require==1?'是':'否'}}
        </template>
      </el-table-column>
      <el-table-column label="排序" align='center'>
        <template slot-scope="item">
          <el-input v-model="item.row.sort" type='number' @blur="attrUpdate(item.row,'sort')"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" width='340' align='center'>
        <template slot-scope="item">
          <el-link type="primary" class="table_btn" @click="handleDetails(item.row)" :underline="false"><i class="iconfont icon-chakan"></i>查看</el-link>
          <el-link type="primary" class="table_btn" @click="handleUpdate(item.row)" :underline="false"><i class="iconfont icon-bianji"></i>编辑</el-link>
          <el-link type="primary" class="table_btn" @click="handleCreateChild(item.row)" :underline="false"><i class="el-icon el-icon-plus"></i>添加属性</el-link>
          <el-link type="danger" class="table_btn" @click="handleDelete(item.row.id)" :underline="false"><i class="iconfont icon-lajitong1"></i>删除</el-link>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      class="pagination-container"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="paginate.current"
      :hide-on-single-page='isHideSingle'
      :page-sizes="paginate.sizes"
      :page-size="paginate.limit"
      :layout="paginate.layout"
      :total="paginate.total"/>
    <!------------------------- 新增，编辑类型 ------------------------------>
    <addLabel ref='addLabel' :title='title'></addLabel>
    <!-- 新增属性 -->
    <addAttr ref='addAttr'></addAttr>
  </div>
</template>

<script>
import formOperate from '@/layout/mixin/formOperate'
import addAttr from '../components/addAttr.vue'
import addLabel from '../components/addLabel.vue'
export default {
  name: 'Index',
  mixins: [formOperate],
  data() {
    return {
      url:'/profession/admin/tagType',
      queryParam:{
        page:1,
        page_index:10,
        parent_id:''
      },
      labelType:'',
      type_name:'',
    }
  },
  mounted() {
    this.labelType = this.$route.query.labelType
    this.queryParam.parent_id = this.$route.query.parent_id
    this.type_name = this.$route.query.type_name
    this.$route.meta.title = this.type_name
  },
  methods: {
    backUp() {
      if (this.labelType > 1) {
        this.$router.go(-1)
      } else {
        this.$router.push({path:'/talents/labelManage'})
      }
    },
    // 修改排序
    attrUpdate(item,type) {
      this.id = item.id
      let param = {}
      param[type] = item[type]
      this.$http.put(this.url + '/' + this.id, param).then((response) => {
        this.handleResponse(response)
      })
    },
    handleCreate() {
      this.$refs.addLabel.show()
    },
    // 添加子属性
    handleCreateChild(item) {
      let param = {
        parent_id:item.parent_id,
        attr_id:item.attr_id,
        attr_name:item.attr_name
      }
      this.$refs.addChildAttr.show(param)
    },
    // 查看子类型列表
    handleDetails(item) {
      let query = {
        labelType:1,
        id:item.id,
        parent_id:item.parent_id,
        type_name:item.type_name
      }
      this.$router.push({path:'/talents/childAttr/1',query:query})
    }
  },
  components: {
    addAttr,
    addLabel
  }
}
</script>
<style lang="scss" scoped>
.isShow{
  margin-bottom:18px;
}
.switch_btn{
  margin-right: 30px;
}
</style>